import {
	requestPointData
} from './postPointData.js'
export default {
	data() {
		return {
			pointPagesPath: ""
		};
	},
	onLoad() {},
	onShow() {
		if (getCurrentPages().length > 0) {
			this.entryTrack();
		}
	},
	onHide() {
		this.leaveTrack();
	},
	onUnload() {
		this.leaveTrack();
	},
	methods: {
		// 进入页面时埋点
		entryTrack() {
			const pointPagesPath = getCurrentPages()[getCurrentPages().length - 1].route;
			this.pointPagesPath = pointPagesPath;
			this.getRequestPointData(pointPagesPath, 'into')
		},
		// 离开页面时埋点
		leaveTrack() {
			this.getRequestPointData(this.pointPagesPath, 'exit')
		},
		// 埋点传参
		getRequestPointData(pageName, action) {
			const t = Math.floor(Date.now() / 1000).toString();
			let obj = {}
			if (pageName == 'jvss/pages/device/home' && action != 'exit') {
				obj = {
					code: '300002',
					EventName: 'page_home',
					t
				}
			} else {
				obj = {
					code: '300001',
					EventName: 'page',
					action,
					pageName,
					t
				}
			} // console.log(obj, action != 'exit' ? '进入埋点' : '离开埋点')
			requestPointData(obj)
		}
	},
};
